//
//  LoginViewController.m
//  fitnessmanage
//
//  Created by 众拳科技 on 2017/10/16.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "LoginViewController.h"
#import "LoginView.h"
#import "LoginDetailViewController.h"
//#import "FitnesssViewController.h"
#import "RegFirstViewController.h"
//#import <UMSocialCore/UMSocialCore.h>
//#import <TLSSDK/TLSHelper.h>
//#import <TLSSDK/TLSLoginHelper.h>
//#import "VerCodeViewController.h"

@interface LoginViewController ()<UINavigationControllerDelegate,ThirdLoginViewDelegate>

@property(nonatomic,weak)LoginView *loginView;

@end

@implementation LoginViewController

-(void)viewWillAppear:(BOOL)animated{
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    
    self.navigationController.delegate = self;
    
    LoginView *loginView = [[LoginView alloc] initWithFrame:self.view.frame];
    
    loginView.thirdLoginView.titleLabel.text = @"其他登录方式";
    
    [loginView.loginBtn addTarget:self action:@selector(goLoginDetail) forControlEvents:UIControlEventTouchUpInside];
    
    [loginView.regBtn addTarget:self action:@selector(registClick) forControlEvents:UIControlEventTouchUpInside];
    
    loginView.thirdLoginView.delegate = self;
    
    [self.view addSubview:loginView];
    
}

#pragma mark 登录详情
-(void)goLoginDetail{
    
    LoginDetailViewController *loginDetailVC = [[LoginDetailViewController alloc] init];
    
    [self.navigationController pushViewController:loginDetailVC animated:YES];
}

#pragma mark 注册按钮点击
-(void)registClick{
    
    RegFirstViewController *regVC = [[RegFirstViewController alloc] init];
    
    [self.navigationController pushViewController:regVC animated:YES];
    
}

//*
//- (void)loginView:(ThirdLoginView *)loginView didSelctedItem:(ThirdLoginType)type
//{
//
//        UMSocialPlatformType UMtype;
//
//        switch (type) {
//            case ThirdLoginTypeQQ:
//                UMtype = UMSocialPlatformType_QQ;
//                break;
//            case ThirdLoginTypeWeChat:
//                UMtype = UMSocialPlatformType_WechatSession;
//                break;
//            case ThirdLoginTypeWeibo:
//                UMtype = UMSocialPlatformType_Sina;
//                break;
//            default:
//                break;
//        }
//
//        //如果需要获得用户信息直接跳转的话，需要先取消授权
//        //step1 取消授权
////        [[UMSocialManager defaultManager] cancelAuthWithPlatform:UMtype completion:^(id result, NSError *error) {
//
//            //step2 获得用户信息(获得用户信息中包含检查授权的信息了)
//            [[UMSocialManager defaultManager] getUserInfoWithPlatform:UMtype currentViewController:self completion:^(id result, NSError *error) {
//
//                NSString *message = nil;
//
//                if (error) {
//                    message = @"Get user info fail";
//                    NSLog(@"Get user info fail with error %@",error);
//                    [MBProgressHUD showText:@"授权失败"];
//                }else{
//                    if ([result isKindOfClass:[UMSocialUserInfoResponse class]]) {
//                        UMSocialUserInfoResponse *resp = result;
//                        // 授权信息
//                        NSLog(@"UserInfoAuthResponse uid: %@", resp.uid);
//                        NSLog(@"UserInfoAuthResponse accessToken: %@", resp.accessToken);
//                        NSLog(@"UserInfoAuthResponse refreshToken: %@", resp.refreshToken);
//                        NSLog(@"UserInfoAuthResponse expiration: %@", resp.expiration);
//
//                        // 用户信息
//                        NSLog(@"UserInfoResponse name: %@", resp.name);
//                        NSLog(@"UserInfoResponse iconurl: %@", resp.iconurl);
//                        NSLog(@"UserInfoResponse gender: %@", resp.gender);
//
//                        // 第三方平台SDK源数据,具体内容视平台而定
//                        //NSLog(@"OriginalUserProfileResponse: %@", resp.originalResponse);
//
//                        message = [NSString stringWithFormat:@"name: %@\n icon: %@\n gender: %@\n",resp.name,resp.iconurl,resp.gender];
//
//                        if (UMtype == UMSocialPlatformType_QQ) {
//
//
//                            UserAccount *userAccount = [UserAccount account];
//
//                            userAccount.Name = resp.openid;
//
//                            userAccount.userPassword = @"";
//
//                            [UserAccount saveAccount:userAccount];
//
//                            //跳转绑定手机页面
//                            VerCodeViewController *verCodeVC = [[VerCodeViewController alloc] init];
//
//                            verCodeVC.from = @"绑定手机";
//
//                            [self.navigationController pushViewController:verCodeVC animated:YES];
//
//                        }
//                        else{
//
//
//                        }
//
//                    }else{
//
//                        message = @"Get user info fail";
//
//                        NSLog(@"Get user info fail with  unknow error");
//                    }
//                }
//            }];
////        }];
//}

#pragma mark UINavationControllerDelegate
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]] || [viewController isKindOfClass:[EngageController class]];
    
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}

- (UIStatusBarStyle)preferredStatusBarStyle {

        return UIStatusBarStyleLightContent;
}
@end
